package com.zxq.frame.modbus.inner;

import com.zxq.factory.annotate.DecoderField;
import com.zxq.factory.annotate.EncoderField;
import com.zxq.factory.annotate.Frame;
import com.zxq.factory.enums.EField;
import com.zxq.factory.enums.ETrimMethod;
import lombok.Data;

import java.util.Arrays;

@Frame
@Data
public class PDU {

    /**
     * 对应iot_cmd 表的 cmdHex
     */
    @EncoderField(sequence = 1,field = EField.Int,len = 1,note = "功能码")
    @DecoderField(sequence = 1,field = EField.Int,param = 1,note = "功能码")
    Integer funCode;

    /**
     * 根据iot_cmd的 id，来配置解析的字段，对用户开放
     */
    @EncoderField(sequence = 2,field = EField.Bytes,note = "数据")
    @DecoderField(sequence = 2,field = EField.Bytes,method = ETrimMethod.Tail,param = 0,note = "数据")
    byte[] data;

    @Override
    public String toString() {
        return "PDU{" +
                "funCode=" + funCode +
                ", data=" + Arrays.toString(data) +
                '}';
    }
}
